//
//  IFScheduStateView.m
//  Medicare
//
//  Created by admin on 2017/8/7.
//  Copyright © 2017年 medicare. All rights reserved.
//

#import "IFScheduStateView.h"
#import "IFSchedulDocListModel.h"
#import "UIView+FitScale.h"
#import "UIImage+CircleImage.h"
#import "UIImage+compress.h"

#import "UIImage+ResetColor.h"
#import "IFMySchedulingPublicDefines.h"

@implementation IFScheduStateView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.upLabel = [[UILabel alloc] init];
        self.downLabel = [[UILabel alloc] init];
        self.bigLabel = [[UILabel alloc] init];
        self.clickBtn = [[UIButton alloc] init];
        self.borderView = [[UIImageView alloc] init];
        self.borderViewLow = [[UIImageView alloc] init];
        self.lineView = [[UIView alloc] init];
        self.bigLabel.textAlignment =
        self.upLabel.textAlignment =
        self.downLabel.textAlignment = NSTextAlignmentCenter;
        self.bigLabel.font = self.upLabel.font
        = self.downLabel.font = [UIFont systemFontOfSize:CGFloatIn375(11.f)];
        [self addSubview:_borderView];
        [self.borderView addSubview:_upLabel];
        [self.borderView addSubview:_downLabel];
        [self.borderView addSubview:_bigLabel];
        [self addSubview:_clickBtn];
        [self.borderView addSubview:_lineView];
        self.lineView.hidden = YES;
        self.clickBtn.backgroundColor = [UIColor clearColor];
        self.bigLabel.backgroundColor = [UIColor clearColor];
        self.upLabel.backgroundColor = [UIColor clearColor];
        self.downLabel.backgroundColor = [UIColor clearColor];
        self.lineView.backgroundColor = [UIColor colorWithHexString:@"d4d4d4"];
        [self addObserver:self forKeyPath:@"isSelect" options:NSKeyValueObservingOptionNew context:nil];
         self.borderView.image = [Common getDocumentImageAndImageName:@"NoEditorPic"];
        
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        self.frame = CGRectMake(0, 0, kScreenWidth/8.f, CGRectGetHeight(self.frame));
        self.upLabel = [[UILabel alloc] init];
        self.downLabel = [[UILabel alloc] init];
        self.bigLabel = [[UILabel alloc] init];
        self.borderView = [[UIImageView alloc] init];
        self.lineView = [[UIView alloc] init];
        [self addSubview:_borderView];
        [self.borderView addSubview:_upLabel];
        [self.borderView addSubview:_downLabel];
        [self.borderView addSubview:_bigLabel];
        [self addSubview:_clickBtn];
        [self.borderView addSubview:_lineView];
        self.lineView.hidden = YES;
        self.lineView.backgroundColor = [UIColor colorWithHexString:@"d4d4d4"];
        [self addObserver:self forKeyPath:@"isSelect" options:NSKeyValueObservingOptionNew context:nil];

      
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.borderView.frame =  CGRectMake(5, 5, CGRectGetWidth(self.frame) - 10, CGRectGetHeight(self.frame) - 10) ;
    self.upLabel.frame =  CGRectMake(0, 0, CGRectGetWidth(self.borderView.frame),CGRectGetHeight(self.borderView.frame)/2.f) ;
    self.downLabel.frame = CGRectMake(0, CGRectGetMaxY(self.upLabel.frame),CGRectGetWidth(self.borderView.frame), CGRectGetHeight(self.borderView.frame)/2.f) ;
    self.bigLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.borderView.frame),CGRectGetHeight(self.borderView.frame)) ;
    self.lineView.frame = CGRectMake(1,CGRectGetHeight(self.borderView.frame)/2,CGRectGetWidth(self.borderView.frame) - 2.0 , 0.5);
    self.clickBtn.frame = CGRectMake(0,0,CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context {
    IFScheduStateView * stateView = (IFScheduStateView *)object;
    if (stateView.isSelect) {
        self.borderView.image = [Common getDocumentImageAndImageName:@"EditorSelectPic"];
    } else {
        self.borderView.image = [Common getDocumentImageAndImageName:@"EditorPic"];
    }
}

- (void)dealloc {
    
    [self removeObserver:self forKeyPath:@"isSelect" context:nil];
}


@end
